package com.ljyh.cygnus

import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.startForegroundService
import com.ljyh.cygnus.screens.MainScreen
import com.ljyh.cygnus.serve.DevicePolicyService

import com.ljyh.cygnus.ui.theme.CygnusTheme
import com.ljyh.cygnus.utils.PolicyManager
import com.topjohnwu.superuser.Shell
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        Shell.enableVerboseLogging = BuildConfig.DEBUG
        Shell.setDefaultBuilder(
            Shell.Builder.create()
                .setFlags(Shell.FLAG_MOUNT_MASTER)
                .setTimeout(10)
        )

        startDevicePolicyService()
        setContent {
            CygnusTheme {
                MainScreen()
            }
        }
    }
    private fun startDevicePolicyService() {
        val serviceIntent = Intent(this, DevicePolicyService::class.java)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            startForegroundService(serviceIntent)
        } else {
            startService(serviceIntent)
        }
    }


}

